# This files contains your custom actions which can be used to run
# custom Python code.
#
# See this guide on how to implement these action:
# https://rasa.com/docs/rasa/custom-actions


# This is a simple example for a custom action which utters "Hello World!"

from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
import graph
from chatgpt import askGPT, askGPT_combine

lim = 20

class ActionGoodbye(Action):

    def name(self) -> Text:
        return "action_goodbye"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        dispatcher.utter_message(text="再见！欢迎再来问我医学问题，我将为您耐心解答，祝您和您的家人身体健康！")
        return []

class Action_Belongs_to(Action):
    def name(self) -> Text:
        return "action_Belongs_to"
    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        relation_type = 'belongs_to'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # 3. 调用graph的相关函数进行三元组查询
        triplets = []
        if entities != []: # 有实体，则查询实体+关系。
            for entity, value in entities:
                triplets.extend(graph.query_search(entity, value, relation_type))
        if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
            triplets.extend(graph.query_relation(relation_type))
        # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        st = 0
        ans_together = []
        while st < len(triplets):
            en = min(st + lim, len(triplets))
            tmp_triplets = triplets[st:en]
            tmp_ans = askGPT(user_input, str(tmp_triplets))
            ans_together.append(tmp_ans)
            st += lim
        # ans = askGPT(user_input, str(triplets))
        ans = askGPT_combine(user_input, str(ans_together))
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")
        return []

class Action_Common_Drug(Action):
    def name(self) -> Text:
        return "action_Common_Drug"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        relation_type = 'common_drug'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # 3. 调用graph的相关函数进行三元组查询
        triplets = []
        if entities != []: # 有实体，则查询实体+关系。
            for entity, value in entities:
                triplets.extend(graph.query_search(entity, value, relation_type))
        if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
            triplets.extend(graph.query_relation(relation_type))

        # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        st = 0
        ans_together = []
        while st < len(triplets):
            en = min(st + lim, len(triplets))
            tmp_triplets = triplets[st:en]
            tmp_ans = askGPT(user_input, str(tmp_triplets))
            ans_together.append(tmp_ans)
            st += lim
        # ans = askGPT(user_input, str(triplets))
        ans = askGPT_combine(user_input, str(ans_together))
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []

class Action_Common_Drug(Action):
    def name(self) -> Text:
        return "action_Common_Drug"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        relation_type = 'common_drug'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # 3. 调用graph的相关函数进行三元组查询
        triplets = []
        if entities != []: # 有实体，则查询实体+关系。
            for entity, value in entities:
                triplets.extend(graph.query_search(entity, value, relation_type))
        if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
            triplets.extend(graph.query_relation(relation_type))

        # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        st = 0
        ans_together = []
        while st < len(triplets):
            en = min(st + lim, len(triplets))
            tmp_triplets = triplets[st:en]
            tmp_ans = askGPT(user_input, str(tmp_triplets))
            ans_together.append(tmp_ans)
            st += lim
        # ans = askGPT(user_input, str(triplets))
        ans = askGPT_combine(user_input, str(ans_together))
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []
class Action_Do_eat(Action):
    def name(self) -> Text:
        return "action_Do_eat"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        relation_type = 'do_eat'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # 3. 调用graph的相关函数进行三元组查询
        triplets = []
        if entities != []: # 有实体，则查询实体+关系。
            for entity, value in entities:
                triplets.extend(graph.query_search(entity, value, relation_type))
        if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
            triplets.extend(graph.query_relation(relation_type))

        # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        st = 0
        ans_together = []
        while st < len(triplets):
            en = min(st + lim, len(triplets))
            tmp_triplets = triplets[st:en]
            tmp_ans = askGPT(user_input, str(tmp_triplets))
            ans_together.append(tmp_ans)
            st += lim
        # ans = askGPT(user_input, str(triplets))
        ans = askGPT_combine(user_input, str(ans_together))
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []

class Action_Need_check(Action):
    def name(self) -> Text:
        return "action_Need_check"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        relation_type = 'need_check'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # 3. 调用graph的相关函数进行三元组查询
        triplets = []
        if entities != []: # 有实体，则查询实体+关系。
            for entity, value in entities:
                triplets.extend(graph.query_search(entity, value, relation_type))
        if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
            triplets.extend(graph.query_relation(relation_type))

        # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        st = 0
        ans_together = []
        while st < len(triplets):
            en = min(st + lim, len(triplets))
            tmp_triplets = triplets[st:en]
            tmp_ans = askGPT(user_input, str(tmp_triplets))
            ans_together.append(tmp_ans)
            st += lim
        # ans = askGPT(user_input, str(triplets))
        ans = askGPT_combine(user_input, str(ans_together))
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []

class Action_No_eat(Action):
    def name(self) -> Text:
        return "action_No_eat"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        relation_type = 'no_eat'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # 3. 调用graph的相关函数进行三元组查询
        triplets = []
        if entities != []: # 有实体，则查询实体+关系。
            for entity, value in entities:
                triplets.extend(graph.query_search(entity, value, relation_type))
        if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
            triplets.extend(graph.query_relation(relation_type))

        # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        st = 0
        ans_together = []
        while st < len(triplets):
            en = min(st + lim, len(triplets))
            tmp_triplets = triplets[st:en]
            tmp_ans = askGPT(user_input, str(tmp_triplets))
            ans_together.append(tmp_ans)
            st += lim
        # ans = askGPT(user_input, str(triplets))
        ans = askGPT_combine(user_input, str(ans_together))
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []

class Action_Has_sympton(Action):
    def name(self) -> Text:
        return "action_Has_sympton"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        relation_type = 'has_sympton'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # 3. 调用graph的相关函数进行三元组查询
        triplets = []
        if entities != []: # 有实体，则查询实体+关系。
            for entity, value in entities:
                triplets.extend(graph.query_search(entity, value, relation_type))
        if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
            triplets.extend(graph.query_relation(relation_type))

        # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        st = 0
        ans_together = []
        while st < len(triplets):
            en = min(st + lim, len(triplets))
            tmp_triplets = triplets[st:en]
            tmp_ans = askGPT(user_input, str(tmp_triplets))
            ans_together.append(tmp_ans)
            st += lim
        # ans = askGPT(user_input, str(triplets))
        ans = askGPT_combine(user_input, str(ans_together))
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []

class Action_Recommend_Drug(Action):
    def name(self) -> Text:
        return "action_Recommend_Drug"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        relation_type = 'recommend_Drug'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # 3. 调用graph的相关函数进行三元组查询
        triplets = []
        if entities != []: # 有实体，则查询实体+关系。
            for entity, value in entities:
                triplets.extend(graph.query_search(entity, value, relation_type))
        if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
            triplets.extend(graph.query_relation(relation_type))

        # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        st = 0
        ans_together = []
        while st < len(triplets):
            en = min(st + lim, len(triplets))
            tmp_triplets = triplets[st:en]
            tmp_ans = askGPT(user_input, str(tmp_triplets))
            ans_together.append(tmp_ans)
            st += lim
        # ans = askGPT(user_input, str(triplets))
        ans = askGPT_combine(user_input, str(ans_together))
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []
class Action_Recommend_eat(Action):
    def name(self) -> Text:
        return "action_Recommend_eat"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        relation_type = 'recommend_eat'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # 3. 调用graph的相关函数进行三元组查询
        triplets = []
        if entities != []: # 有实体，则查询实体+关系。
            for entity, value in entities:
                triplets.extend(graph.query_search(entity, value, relation_type))
        if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
            triplets.extend(graph.query_relation(relation_type))

        # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        st = 0
        ans_together = []
        while st < len(triplets):
            en = min(st + lim, len(triplets))
            tmp_triplets = triplets[st:en]
            tmp_ans = askGPT(user_input, str(tmp_triplets))
            ans_together.append(tmp_ans)
            st += lim
        # ans = askGPT(user_input, str(triplets))
        ans = askGPT_combine(user_input, str(ans_together))
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []

class Action_Accompany_with(Action):
    def name(self) -> Text:
        return "action_Accompany_with"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        relation_type = 'accompany_with'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # 3. 调用graph的相关函数进行三元组查询
        triplets = []
        if entities != []: # 有实体，则查询实体+关系。
            for entity, value in entities:
                triplets.extend(graph.query_search(entity, value, relation_type))
        if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
            triplets.extend(graph.query_relation(relation_type))

        # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        st = 0
        ans_together = []
        while st < len(triplets):
            en = min(st + lim, len(triplets))
            tmp_triplets = triplets[st:en]
            tmp_ans = askGPT(user_input, str(tmp_triplets))
            ans_together.append(tmp_ans)
            st += lim
        # ans = askGPT(user_input, str(triplets))
        ans = askGPT_combine(user_input, str(ans_together))
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []

class Action_Desc(Action):
    def name(self) -> Text:
        return "action_Desc"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        property_type = 'desc'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # region old_use_relation
        # # 3. 调用graph的相关函数进行三元组查询
        # triplets = []
        # if entities != []: # 有实体，则查询实体+关系。
        #     for entity, value in entities:
        #         triplets.extend(graph.query_search(entity, value, relation_type))
        # if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
        #     triplets.extend(graph.query_relation(relation_type))
        #
        # # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        # st = 0
        # ans_together = []
        # while st < len(triplets):
        #     en = min(st + lim, len(triplets))
        #     tmp_triplets = triplets[st:en]
        #     tmp_ans = askGPT(user_input, str(tmp_triplets))
        #     ans_together.append(tmp_ans)
        #     st += lim
        # # ans = askGPT(user_input, str(triplets))
        # ans = askGPT_combine(user_input, str(ans_together))
        # endregion
        ans = ""
        for entity, value in entities:
            ans = ans + graph.property_search(entity, value, property_type)
            ans = ans + "\n"
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []

class Action_Desc(Action):
    def name(self) -> Text:
        return "action_Desc"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        property_type = 'desc'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # region old_use_relation
        # # 3. 调用graph的相关函数进行三元组查询
        # triplets = []
        # if entities != []: # 有实体，则查询实体+关系。
        #     for entity, value in entities:
        #         triplets.extend(graph.query_search(entity, value, relation_type))
        # if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
        #     triplets.extend(graph.query_relation(relation_type))
        #
        # # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        # st = 0
        # ans_together = []
        # while st < len(triplets):
        #     en = min(st + lim, len(triplets))
        #     tmp_triplets = triplets[st:en]
        #     tmp_ans = askGPT(user_input, str(tmp_triplets))
        #     ans_together.append(tmp_ans)
        #     st += lim
        # # ans = askGPT(user_input, str(triplets))
        # ans = askGPT_combine(user_input, str(ans_together))
        # endregion
        ans = ""
        for entity, value in entities:
            ans = ans + graph.property_search(entity, value, property_type)
            ans = ans + "\n"
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []
class Action_Cause(Action):
    def name(self) -> Text:
        return "action_Cause"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        property_type = 'cause'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # region old_use_relation
        # # 3. 调用graph的相关函数进行三元组查询
        # triplets = []
        # if entities != []: # 有实体，则查询实体+关系。
        #     for entity, value in entities:
        #         triplets.extend(graph.query_search(entity, value, relation_type))
        # if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
        #     triplets.extend(graph.query_relation(relation_type))
        #
        # # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        # st = 0
        # ans_together = []
        # while st < len(triplets):
        #     en = min(st + lim, len(triplets))
        #     tmp_triplets = triplets[st:en]
        #     tmp_ans = askGPT(user_input, str(tmp_triplets))
        #     ans_together.append(tmp_ans)
        #     st += lim
        # # ans = askGPT(user_input, str(triplets))
        # ans = askGPT_combine(user_input, str(ans_together))
        # endregion
        ans = ""
        for entity, value in entities:
            ans = ans + graph.property_search(entity, value, property_type)
            ans = ans + "\n"
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []

class Action_Prevent(Action):
    def name(self) -> Text:
        return "action_Prevent"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        property_type = 'prevent'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # region old_use_relation
        # # 3. 调用graph的相关函数进行三元组查询
        # triplets = []
        # if entities != []: # 有实体，则查询实体+关系。
        #     for entity, value in entities:
        #         triplets.extend(graph.query_search(entity, value, relation_type))
        # if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
        #     triplets.extend(graph.query_relation(relation_type))
        #
        # # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        # st = 0
        # ans_together = []
        # while st < len(triplets):
        #     en = min(st + lim, len(triplets))
        #     tmp_triplets = triplets[st:en]
        #     tmp_ans = askGPT(user_input, str(tmp_triplets))
        #     ans_together.append(tmp_ans)
        #     st += lim
        # # ans = askGPT(user_input, str(triplets))
        # ans = askGPT_combine(user_input, str(ans_together))
        # endregion
        ans = ""
        for entity, value in entities:
            ans = ans + graph.property_search(entity, value, property_type)
            ans = ans + "\n"
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []

class Action_Cure_lasttime(Action):
    def name(self) -> Text:
        return "action_Cure_lasttime"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        property_type = 'cure_lasttime'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # region old_use_relation
        # # 3. 调用graph的相关函数进行三元组查询
        # triplets = []
        # if entities != []: # 有实体，则查询实体+关系。
        #     for entity, value in entities:
        #         triplets.extend(graph.query_search(entity, value, relation_type))
        # if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
        #     triplets.extend(graph.query_relation(relation_type))
        #
        # # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        # st = 0
        # ans_together = []
        # while st < len(triplets):
        #     en = min(st + lim, len(triplets))
        #     tmp_triplets = triplets[st:en]
        #     tmp_ans = askGPT(user_input, str(tmp_triplets))
        #     ans_together.append(tmp_ans)
        #     st += lim
        # # ans = askGPT(user_input, str(triplets))
        # ans = askGPT_combine(user_input, str(ans_together))
        # endregion
        ans = ""
        for entity, value in entities:
            ans = ans + graph.property_search(entity, value, property_type)
            ans = ans + "\n"
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []

class Action_Cure_way(Action):
    def name(self) -> Text:
        return "action_Cure_way"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        property_type = 'cure_way'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # region old_use_relation
        # # 3. 调用graph的相关函数进行三元组查询
        # triplets = []
        # if entities != []: # 有实体，则查询实体+关系。
        #     for entity, value in entities:
        #         triplets.extend(graph.query_search(entity, value, relation_type))
        # if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
        #     triplets.extend(graph.query_relation(relation_type))
        #
        # # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        # st = 0
        # ans_together = []
        # while st < len(triplets):
        #     en = min(st + lim, len(triplets))
        #     tmp_triplets = triplets[st:en]
        #     tmp_ans = askGPT(user_input, str(tmp_triplets))
        #     ans_together.append(tmp_ans)
        #     st += lim
        # # ans = askGPT(user_input, str(triplets))
        # ans = askGPT_combine(user_input, str(ans_together))
        # endregion
        ans = ""
        for entity, value in entities:
            ans = ans + graph.property_search(entity, value, property_type)
            ans = ans + "\n"
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []

class Action_Cured_prob(Action):
    def name(self) -> Text:
        return "action_Cured_prob"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        property_type = 'cured_prob'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # region old_use_relation
        # # 3. 调用graph的相关函数进行三元组查询
        # triplets = []
        # if entities != []: # 有实体，则查询实体+关系。
        #     for entity, value in entities:
        #         triplets.extend(graph.query_search(entity, value, relation_type))
        # if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
        #     triplets.extend(graph.query_relation(relation_type))
        #
        # # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        # st = 0
        # ans_together = []
        # while st < len(triplets):
        #     en = min(st + lim, len(triplets))
        #     tmp_triplets = triplets[st:en]
        #     tmp_ans = askGPT(user_input, str(tmp_triplets))
        #     ans_together.append(tmp_ans)
        #     st += lim
        # # ans = askGPT(user_input, str(triplets))
        # ans = askGPT_combine(user_input, str(ans_together))
        # endregion
        ans = ""
        for entity, value in entities:
            ans = ans + graph.property_search(entity, value, property_type)
            ans = ans + "\n"
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []

class Action_Easy_get(Action):
    def name(self) -> Text:
        return "action_Easy_get"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        property_type = 'easy_get'
        user_input = tracker.latest_message['text'] # 用户的问题
        # 2. 取出nlu中的实体识别结果
        entities_ori = tracker.latest_message['entities']
        entities = []
        for item in entities_ori:
            entities.append((str(item['entity']), str(item['value'])))
        # region old_use_relation
        # # 3. 调用graph的相关函数进行三元组查询
        # triplets = []
        # if entities != []: # 有实体，则查询实体+关系。
        #     for entity, value in entities:
        #         triplets.extend(graph.query_search(entity, value, relation_type))
        # if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
        #     triplets.extend(graph.query_relation(relation_type))
        #
        # # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
        # # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
        # st = 0
        # ans_together = []
        # while st < len(triplets):
        #     en = min(st + lim, len(triplets))
        #     tmp_triplets = triplets[st:en]
        #     tmp_ans = askGPT(user_input, str(tmp_triplets))
        #     ans_together.append(tmp_ans)
        #     st += lim
        # # ans = askGPT(user_input, str(triplets))
        # ans = askGPT_combine(user_input, str(ans_together))
        # endregion
        ans = ""
        for entity, value in entities:
            ans = ans + graph.property_search(entity, value, property_type)
            ans = ans + "\n"
        if ans != "":
            dispatcher.utter_message(text=ans)
        else:
            dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")

        return []
# class Action_Test_Disease(Action):
#     def name(self) -> Text:
#         return "action_Test_Disease"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#         relation_type = 'Test_Disease'
#         user_input = tracker.latest_message['text'] # 用户的问题
#         # 2. 取出nlu中的实体识别结果
#         entities_ori = tracker.latest_message['entities']
#         entities = []
#         for item in entities_ori:
#             entities.append((str(item['entity']), str(item['value'])))
#         # 3. 调用graph的相关函数进行三元组查询
#         triplets = []
#         if entities != []: # 有实体，则查询实体+关系。
#             for entity, value in entities:
#                 triplets.extend(graph.query_search(entity, value, relation_type))
#         if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
#             triplets.extend(graph.query_relation(relation_type))
#
#         # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
#         # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
#         st = 0
#         ans_together = []
#         while st < len(triplets):
#             en = min(st + lim, len(triplets))
#             tmp_triplets = triplets[st:en]
#             tmp_ans = askGPT(user_input, str(tmp_triplets))
#             ans_together.append(tmp_ans)
#             st += lim
#         # ans = askGPT(user_input, str(triplets))
#         ans = askGPT_combine(user_input, str(ans_together))
#         if ans != "":
#             dispatcher.utter_message(text=ans)
#         else:
#             dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")
#
#         return []
#
# class Action_Symptom_Disease(Action):
#     def name(self) -> Text:
#         return "action_Symptom_Disease"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#         relation_type = 'Symptom_Disease'
#         user_input = tracker.latest_message['text'] # 用户的问题
#         # 2. 取出nlu中的实体识别结果
#         entities_ori = tracker.latest_message['entities']
#         entities = []
#         for item in entities_ori:
#             entities.append((str(item['entity']), str(item['value'])))
#         # 3. 调用graph的相关函数进行三元组查询
#         triplets = []
#         if entities != []: # 有实体，则查询实体+关系。
#             for entity, value in entities:
#                 triplets.extend(graph.query_search(entity, value, relation_type))
#         if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
#             triplets.extend(graph.query_relation(relation_type))
#
#         # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
#         # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
#         st = 0
#         ans_together = []
#         while st < len(triplets):
#             en = min(st + lim, len(triplets))
#             tmp_triplets = triplets[st:en]
#             tmp_ans = askGPT(user_input, str(tmp_triplets))
#             ans_together.append(tmp_ans)
#             st += lim
#         # ans = askGPT(user_input, str(triplets))
#         ans = askGPT_combine(user_input, str(ans_together))
#         if ans != "":
#             dispatcher.utter_message(text=ans)
#         else:
#             dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")
#
#         return []
#
# class Action_Treatment_Disease(Action):
#     def name(self) -> Text:
#         return "action_Treatment_Disease"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#         relation_type = 'Treatment_Disease'
#         user_input = tracker.latest_message['text'] # 用户的问题
#         # 2. 取出nlu中的实体识别结果
#         entities_ori = tracker.latest_message['entities']
#         entities = []
#         for item in entities_ori:
#             entities.append((str(item['entity']), str(item['value'])))
#         # 3. 调用graph的相关函数进行三元组查询
#         triplets = []
#         if entities != []: # 有实体，则查询实体+关系。
#             for entity, value in entities:
#                 triplets.extend(graph.query_search(entity, value, relation_type))
#         if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
#             triplets.extend(graph.query_relation(relation_type))
#
#         # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
#         # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
#         st = 0
#         ans_together = []
#         while st < len(triplets):
#             en = min(st + lim, len(triplets))
#             tmp_triplets = triplets[st:en]
#             tmp_ans = askGPT(user_input, str(tmp_triplets))
#             ans_together.append(tmp_ans)
#             st += lim
#         # ans = askGPT(user_input, str(triplets))
#         ans = askGPT_combine(user_input, str(ans_together))
#         if ans != "":
#             dispatcher.utter_message(text=ans)
#         else:
#             dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")
#
#         return []
#
#
# class Action_Drug_Disease(Action):
#     def name(self) -> Text:
#         return "action_Drug_Disease"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#         relation_type = 'Drug_Disease'
#         user_input = tracker.latest_message['text'] # 用户的问题
#         # 2. 取出nlu中的实体识别结果
#         entities_ori = tracker.latest_message['entities']
#         entities = []
#         for item in entities_ori:
#             entities.append((str(item['entity']), str(item['value'])))
#         # 3. 调用graph的相关函数进行三元组查询
#         triplets = []
#         if entities != []: # 有实体，则查询实体+关系。
#             for entity, value in entities:
#                 triplets.extend(graph.query_search(entity, value, relation_type))
#         if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
#             triplets.extend(graph.query_relation(relation_type))
#
#         # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
#         # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
#         st = 0
#         ans_together = []
#         while st < len(triplets):
#             en = min(st + lim, len(triplets))
#             tmp_triplets = triplets[st:en]
#             tmp_ans = askGPT(user_input, str(tmp_triplets))
#             ans_together.append(tmp_ans)
#             st += lim
#         # ans = askGPT(user_input, str(triplets))
#         ans = askGPT_combine(user_input, str(ans_together))
#         if ans != "":
#             dispatcher.utter_message(text=ans)
#         else:
#             dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")
#
#         return []
#
# class Action_Anatomy_Disease(Action):
#     def name(self) -> Text:
#         return "action_Anatomy_Disease"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#         relation_type = 'Anatomy_Disease'
#         user_input = tracker.latest_message['text'] # 用户的问题
#         # 2. 取出nlu中的实体识别结果
#         entities_ori = tracker.latest_message['entities']
#         entities = []
#         for item in entities_ori:
#             entities.append((str(item['entity']), str(item['value'])))
#         # 3. 调用graph的相关函数进行三元组查询
#         triplets = []
#         if entities != []: # 有实体，则查询实体+关系。
#             for entity, value in entities:
#                 triplets.extend(graph.query_search(entity, value, relation_type))
#         if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
#             triplets.extend(graph.query_relation(relation_type))
#
#         # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
#         # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
#         st = 0
#         ans_together = []
#         while st < len(triplets):
#             en = min(st + lim, len(triplets))
#             tmp_triplets = triplets[st:en]
#             tmp_ans = askGPT(user_input, str(tmp_triplets))
#             ans_together.append(tmp_ans)
#             st += lim
#         # ans = askGPT(user_input, str(triplets))
#         ans = askGPT_combine(user_input, str(ans_together))
#         if ans != "":
#             dispatcher.utter_message(text=ans)
#         else:
#             dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")
#
#         return []
#
# class Action_Reason_Disease(Action):
#     def name(self) -> Text:
#         return "action_Reason_Disease"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#         relation_type = 'Reason_Disease'
#         user_input = tracker.latest_message['text'] # 用户的问题
#         # 2. 取出nlu中的实体识别结果
#         entities_ori = tracker.latest_message['entities']
#         entities = []
#         for item in entities_ori:
#             entities.append((str(item['entity']), str(item['value'])))
#         # 3. 调用graph的相关函数进行三元组查询
#         triplets = []
#         if entities != []: # 有实体，则查询实体+关系。
#             for entity, value in entities:
#                 triplets.extend(graph.query_search(entity, value, relation_type))
#         if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
#             triplets.extend(graph.query_relation(relation_type))
#
#         # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
#         # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
#         st = 0
#         ans_together = []
#         while st < len(triplets):
#             en = min(st + lim, len(triplets))
#             tmp_triplets = triplets[st:en]
#             tmp_ans = askGPT(user_input, str(tmp_triplets))
#             ans_together.append(tmp_ans)
#             st += lim
#         # ans = askGPT(user_input, str(triplets))
#         ans = askGPT_combine(user_input, str(ans_together))
#         if ans != "":
#             dispatcher.utter_message(text=ans)
#         else:
#             dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")
#
#         return []
#
#
# class Action_Pathogenesis_Disease(Action):
#     def name(self) -> Text:
#         return "action_Pathogenesis_Disease"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#         relation_type = 'Pathogenesis_Disease'
#         user_input = tracker.latest_message['text'] # 用户的问题
#         # 2. 取出nlu中的实体识别结果
#         entities_ori = tracker.latest_message['entities']
#         entities = []
#         for item in entities_ori:
#             entities.append((str(item['entity']), str(item['value'])))
#         # 3. 调用graph的相关函数进行三元组查询
#         triplets = []
#         if entities != []: # 有实体，则查询实体+关系。
#             for entity, value in entities:
#                 triplets.extend(graph.query_search(entity, value, relation_type))
#         if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
#             triplets.extend(graph.query_relation(relation_type))
#
#         # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
#         # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
#         st = 0
#         ans_together = []
#         while st < len(triplets):
#             en = min(st + lim, len(triplets))
#             tmp_triplets = triplets[st:en]
#             tmp_ans = askGPT(user_input, str(tmp_triplets))
#             ans_together.append(tmp_ans)
#             st += lim
#         # ans = askGPT(user_input, str(triplets))
#         ans = askGPT_combine(user_input, str(ans_together))
#         if ans != "":
#             dispatcher.utter_message(text=ans)
#         else:
#             dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")
#
#         return []
#
# class Action_Operation_Disease(Action):
#     def name(self) -> Text:
#         return "action_Operation_Disease"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#         relation_type = 'Operation_Disease'
#         user_input = tracker.latest_message['text'] # 用户的问题
#         # 2. 取出nlu中的实体识别结果
#         entities_ori = tracker.latest_message['entities']
#         entities = []
#         for item in entities_ori:
#             entities.append((str(item['entity']), str(item['value'])))
#         # 3. 调用graph的相关函数进行三元组查询
#         triplets = []
#         if entities != []: # 有实体，则查询实体+关系。
#             for entity, value in entities:
#                 triplets.extend(graph.query_search(entity, value, relation_type))
#         if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
#             triplets.extend(graph.query_relation(relation_type))
#
#         # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
#         # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
#         st = 0
#         ans_together = []
#         while st < len(triplets):
#             en = min(st + lim, len(triplets))
#             tmp_triplets = triplets[st:en]
#             tmp_ans = askGPT(user_input, str(tmp_triplets))
#             ans_together.append(tmp_ans)
#             st += lim
#         # ans = askGPT(user_input, str(triplets))
#         ans = askGPT_combine(user_input, str(ans_together))
#         if ans != "":
#             dispatcher.utter_message(text=ans)
#         else:
#             dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")
#
#         return []
#
# class Action_Class_Disease(Action):
#     def name(self) -> Text:
#         return "action_Class_Disease"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#         relation_type = 'Class_Disease'
#         user_input = tracker.latest_message['text'] # 用户的问题
#         # 2. 取出nlu中的实体识别结果
#         entities_ori = tracker.latest_message['entities']
#         entities = []
#         for item in entities_ori:
#             entities.append((str(item['entity']), str(item['value'])))
#         # 3. 调用graph的相关函数进行三元组查询
#         triplets = []
#         if entities != []: # 有实体，则查询实体+关系。
#             for entity, value in entities:
#                 triplets.extend(graph.query_search(entity, value, relation_type))
#         if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
#             triplets.extend(graph.query_relation(relation_type))
#
#         # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
#         # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
#         st = 0
#         ans_together = []
#         while st < len(triplets):
#             en = min(st + lim, len(triplets))
#             tmp_triplets = triplets[st:en]
#             tmp_ans = askGPT(user_input, str(tmp_triplets))
#             ans_together.append(tmp_ans)
#             st += lim
#         # ans = askGPT(user_input, str(triplets))
#         ans = askGPT_combine(user_input, str(ans_together))
#         if ans != "":
#             dispatcher.utter_message(text=ans)
#         else:
#             dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")
#
#         return []
#
# class Action_Test_Items_Disease(Action):
#     def name(self) -> Text:
#         return "action_Test_Items_Disease"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#         relation_type = 'Test_items_Disease'
#         user_input = tracker.latest_message['text'] # 用户的问题
#         # 2. 取出nlu中的实体识别结果
#         entities_ori = tracker.latest_message['entities']
#         entities = []
#         for item in entities_ori:
#             entities.append((str(item['entity']), str(item['value'])))
#         # 3. 调用graph的相关函数进行三元组查询
#         triplets = []
#         if entities != []: # 有实体，则查询实体+关系。
#             for entity, value in entities:
#                 triplets.extend(graph.query_search(entity, value, relation_type))
#         if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
#             triplets.extend(graph.query_relation(relation_type))
#
#         # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
#         # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
#         st = 0
#         ans_together = []
#         while st < len(triplets):
#             en = min(st + lim, len(triplets))
#             tmp_triplets = triplets[st:en]
#             tmp_ans = askGPT(user_input, str(tmp_triplets))
#             ans_together.append(tmp_ans)
#             st += lim
#         # ans = askGPT(user_input, str(triplets))
#         ans = askGPT_combine(user_input, str(ans_together))
#         if ans != "":
#             dispatcher.utter_message(text=ans)
#         else:
#             dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")
#
#         return []
#
# class Action_Frequency_Drug(Action):
#     def name(self) -> Text:
#         return "action_Frequency_Drug"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#         relation_type = 'Frequency_Drug'
#         user_input = tracker.latest_message['text'] # 用户的问题
#         # 2. 取出nlu中的实体识别结果
#         entities_ori = tracker.latest_message['entities']
#         entities = []
#         for item in entities_ori:
#             entities.append((str(item['entity']), str(item['value'])))
#         # 3. 调用graph的相关函数进行三元组查询
#         triplets = []
#         if entities != []: # 有实体，则查询实体+关系。
#             for entity, value in entities:
#                 triplets.extend(graph.query_search(entity, value, relation_type))
#         if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
#             triplets.extend(graph.query_relation(relation_type))
#
#         # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
#         # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
#         st = 0
#         ans_together = []
#         while st < len(triplets):
#             en = min(st + lim, len(triplets))
#             tmp_triplets = triplets[st:en]
#             tmp_ans = askGPT(user_input, str(tmp_triplets))
#             ans_together.append(tmp_ans)
#             st += lim
#         # ans = askGPT(user_input, str(triplets))
#         ans = askGPT_combine(user_input, str(ans_together))
#         if ans != "":
#             dispatcher.utter_message(text=ans)
#         else:
#             dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")
#
#         return []
#
# class Action_Duration_Drug(Action):
#     def name(self) -> Text:
#         return "action_Duration_Drug"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#         relation_type = 'Duration_Drug'
#         user_input = tracker.latest_message['text'] # 用户的问题
#         # 2. 取出nlu中的实体识别结果
#         entities_ori = tracker.latest_message['entities']
#         entities = []
#         for item in entities_ori:
#             entities.append((str(item['entity']), str(item['value'])))
#         # 3. 调用graph的相关函数进行三元组查询
#         triplets = []
#         if entities != []: # 有实体，则查询实体+关系。
#             for entity, value in entities:
#                 triplets.extend(graph.query_search(entity, value, relation_type))
#         if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
#             triplets.extend(graph.query_relation(relation_type))
#
#         # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
#         # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
#         st = 0
#         ans_together = []
#         while st < len(triplets):
#             en = min(st + lim, len(triplets))
#             tmp_triplets = triplets[st:en]
#             tmp_ans = askGPT(user_input, str(tmp_triplets))
#             ans_together.append(tmp_ans)
#             st += lim
#         # ans = askGPT(user_input, str(triplets))
#         ans = askGPT_combine(user_input, str(ans_together))
#         if ans != "":
#             dispatcher.utter_message(text=ans)
#         else:
#             dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")
#
#         return []
#
# class Action_Amount_Drug(Action):
#     def name(self) -> Text:
#         return "action_Amount_Drug"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#         relation_type = 'Amount_Drug'
#         user_input = tracker.latest_message['text'] # 用户的问题
#         # 2. 取出nlu中的实体识别结果
#         entities_ori = tracker.latest_message['entities']
#         entities = []
#         for item in entities_ori:
#             entities.append((str(item['entity']), str(item['value'])))
#         # 3. 调用graph的相关函数进行三元组查询
#         triplets = []
#         if entities != []: # 有实体，则查询实体+关系。
#             for entity, value in entities:
#                 triplets.extend(graph.query_search(entity, value, relation_type))
#         if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
#             triplets.extend(graph.query_relation(relation_type))
#
#         # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
#         # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
#         st = 0
#         ans_together = []
#         while st < len(triplets):
#             en = min(st + lim, len(triplets))
#             tmp_triplets = triplets[st:en]
#             tmp_ans = askGPT(user_input, str(tmp_triplets))
#             ans_together.append(tmp_ans)
#             st += lim
#         # ans = askGPT(user_input, str(triplets))
#         ans = askGPT_combine(user_input, str(ans_together))
#         if ans != "":
#             dispatcher.utter_message(text=ans)
#         else:
#             dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")
#
#         return []
#
# class Action_Method_Drug(Action):
#     def name(self) -> Text:
#         return "action_Method_Drug"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#         relation_type = 'Method_Drug'
#         user_input = tracker.latest_message['text'] # 用户的问题
#         # 2. 取出nlu中的实体识别结果
#         entities_ori = tracker.latest_message['entities']
#         entities = []
#         for item in entities_ori:
#             entities.append((str(item['entity']), str(item['value'])))
#         # 3. 调用graph的相关函数进行三元组查询
#         triplets = []
#         if entities != []: # 有实体，则查询实体+关系。
#             for entity, value in entities:
#                 triplets.extend(graph.query_search(entity, value, relation_type))
#         if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
#             triplets.extend(graph.query_relation(relation_type))
#
#         # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
#         # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
#         st = 0
#         ans_together = []
#         while st < len(triplets):
#             en = min(st + lim, len(triplets))
#             tmp_triplets = triplets[st:en]
#             tmp_ans = askGPT(user_input, str(tmp_triplets))
#             ans_together.append(tmp_ans)
#             st += lim
#         # ans = askGPT(user_input, str(triplets))
#         ans = askGPT_combine(user_input, str(ans_together))
#         if ans != "":
#             dispatcher.utter_message(text=ans)
#         else:
#             dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")
#
#         return []
#
# class Action_ADE_Drug(Action):
#     def name(self) -> Text:
#         return "action_ADE_Drug"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#         relation_type = 'ADE_Drug'
#         user_input = tracker.latest_message['text'] # 用户的问题
#         # 2. 取出nlu中的实体识别结果
#         entities_ori = tracker.latest_message['entities']
#         entities = []
#         for item in entities_ori:
#             entities.append((str(item['entity']), str(item['value'])))
#         # 3. 调用graph的相关函数进行三元组查询
#         triplets = []
#         if entities != []: # 有实体，则查询实体+关系。
#             for entity, value in entities:
#                 triplets.extend(graph.query_search(entity, value, relation_type))
#         if not triplets: # 如果没查到三元组，就把该关系下的所有三元组返回
#             triplets.extend(graph.query_relation(relation_type))
#
#         # 4. 调用GPT，结合用户问题和查到的信息进行完整回答。
#         # prompt可以这样写：每次传一部分三元组进去，让它回答。再把每次的回答拼起来，让它整合成一段话，应该不太容易超字数。
#         st = 0
#         ans_together = []
#         while st < len(triplets):
#             en = min(st + lim, len(triplets))
#             tmp_triplets = triplets[st:en]
#             tmp_ans = askGPT(user_input, str(tmp_triplets))
#             ans_together.append(tmp_ans)
#             st += lim
#         # ans = askGPT(user_input, str(triplets))
#         ans = askGPT_combine(user_input, str(ans_together))
#         if ans != "":
#             dispatcher.utter_message(text=ans)
#         else:
#             dispatcher.utter_message(text="抱歉，我并不了解这个问题，请咨询医生寻求解答。")
#
#         return []